package com.matt.controller.pad;

import com.matt.commons.model.StatusResponse;
import com.matt.service.remoteCall.DTO.AppEditionDTO;
import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import static com.matt.foundation.constant.RequestConstant.TICKET;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/1
 * *******************************
 */
@RestController
@RequestMapping("/pad/app_edition")
@Api(tags ="pad - app版本")

public class PadAppEditionController {

    @Autowired
    private SsoCallService ssoCallService;


    @ApiOperation(value = "检查是否有更高版本",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "ticket", value = "票据", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "appId", value = "appId", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "appVersion", value = "应用的版本号", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "手机型号：1安卓，2苹果", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "query", name = "wgtVersion", value = "内容包的版本号", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code = 000000, message = "成功"),
            @ApiResponse(code = 000001, message = "ticket已过期")
    })
    @RequestMapping("/replace")
    public StatusResponse replace(@RequestHeader(TICKET) String ticket, String appId,String appVersion,Integer type,String wgtVersion) {
        AppEditionDTO edition = ssoCallService.getEditionCode(ticket,appId,appVersion,type,wgtVersion);
        if (null != edition){
            edition.setIsMandatory(edition.getRenew().equals("是")? 1 : 0  );
        }
        return StatusResponse.success(edition);
    }


}
